package com.ruix.app.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/5/9.
 */

public class ClassCourse {
    private boolean desc; //顺序
    private long totalLesson;
    private long currentLesson;
    private ArrayList<Course> courses;


    public ClassCourse parse(JSONObject object){
        if (object != null){
            setTotalLesson(object.optInt("total_lessons",0));
            setCurrentLesson(object.optInt("current_lessons",0));
            JSONArray array =  object.optJSONArray("courses");
            if (array != null && array.length() > 0){
                courses = new ArrayList<>();
                for (int i = 0; i < array.length() ; i++) {
                    Course course = new Course().parse(array.optJSONObject(i));
                    courses.add(course);
//                    courses.add(course);
//                    courses.add(course);
                }
            }
        }
        return this;
    }


    public long getTotalLesson() {
        return totalLesson;
    }

    public void setTotalLesson(long totalLesson) {
        this.totalLesson = totalLesson;
    }

    public long getCurrentLesson() {
        return currentLesson;
    }

    public void setCurrentLesson(long currentLesson) {
        this.currentLesson = currentLesson;
    }

    public ArrayList<Course> getCourses() {
        return courses;
    }

    public void setCourses(ArrayList<Course> courses) {
        this.courses = courses;
    }

    public boolean isDesc() {
        return desc;
    }

    public void setDesc(boolean desc) {
        this.desc = desc;
    }

    public String getCouseNumInfo(){
        return String.format("更新到%d/%d课",currentLesson,totalLesson);
    }


    @Override
    public String toString() {
        return "ClassCourse{" +
                "totalLesson=" + totalLesson +
                ", currentLesson=" + currentLesson +
                ", courses=" + courses +
                '}';
    }
}
